<template>

  <a-modal v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width" :ok-text="LAYER.okText"
           :align-center="LAYER.alignCenter" :top="LAYER.top" :footer="false"
           :closable="LAYER.closable" :unmount-on-close="false"
           :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose" :ok-loading="LAYER.okLoading"
           @cancel="onClose()">

    <a-list :bordered="false" size="small">
      <a-list-item v-for="(item ,index) in dataList" :key="index">
        <a-list-item-meta :title="item.label +'模块' "/>
        <template #actions>
          <a-link @click="downLoad(item,1)"> 权限表达式下载</a-link>
        </template>
      </a-list-item>
    </a-list>

  </a-modal>

</template>
<script lang="ts" setup>

import {ref} from "vue";
import {saveAs} from "file-saver";
import {LocalModal} from "@/libs/core";
import {MsgUtil, RequestUtil} from "@/utils";
import {SystemOptions} from "@/libs/options";
import {SystemHttp} from "../resource/http";

const emit = defineEmits(['cancel'])


const title = '前端资源下载'
const service = new LocalModal(emit).setMD(title, '保存设置', 600)
const {LAYER} = service
const dataList = ref([])

const loadList = async () => {
  const {data} = await RequestUtil.getAjax(SystemOptions.ModuleOptions)
  dataList.value = data

}

loadList()
const onClose = () => {
  LAYER.visible = false
  emit('cancel', 'NONE')
}

const downLoad = async (record, fileType) => {


    const {message, data} = await SystemHttp.downLoadApi({
      moduleCode: record.value, type: fileType
    })
    if (data.length) {
      const blob = new Blob([data], {type: 'application/javascript'})
      saveAs(blob, 'acl.ts')
    } else {
      MsgUtil.notify('操作失败', message, 'error')
    }


}

</script>

